package designer.single;

/**
 * 在懒汉的模式添加同步模块 可以实现基本的同步
 * Created by tanlee on 2016/4/6.
 */
public class Singleton3 {

    private  static Singleton3 singleton3;

    private Singleton3() {

    }

    synchronized public static Singleton3 getInstance(){
        // 这样生成的对象不是同步的,最后生成的hashcode不是同步的
        try{
            if(singleton3 == null){
                Thread.sleep(3000);
                singleton3 = new Singleton3();
            }
        }
        catch (InterruptedException e){
            e.printStackTrace();
        }
        return  singleton3;
    }
}
